#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#include "MainProc.h"

CMainProc *g_pMainProc = nullptr;

void stop(int signo)
{
    if ((SIGINT == signo) && (nullptr != g_pMainProc))
    {
        g_pMainProc->Stop();
    }
}

int main()
{
    int iRet = EXIT_SUCCESS;
    CMainProc *mp = nullptr;
    pid_t pid = getpid();

    printf("Application started, pid=%d\n", pid);
    mp = new CMainProc();

    if (nullptr == mp)
        return EXIT_FAILURE;

    g_pMainProc = mp;
    sigset(SIGINT, stop);

    if (!mp->Init())
        return EXIT_FAILURE;

    if (!mp->Start())
        return EXIT_FAILURE;

    mp->Destroy();
    delete mp;
    printf("The program has finished running, pid=%d\n", pid);

    return iRet;
}